<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>必填项、邮箱合法性验证</title>
    <script type="text/javascript">
        function validate_mail() {
            var mail =document.getElementById("email").value
            if (mail == ""){
                alert("Email 不能为空！");
                return false;
            }
            if (mail.indexOf("@") == -1){
                alert("Email 格式不正确必须包含“‘@’！");
                return false;
            }
            if (mail.indexOf(".") == -1){
                alert("Email 格式不正确必须包含“”‘.’! ");
            }
            return true;
        }
    </script>
</head>
<body>
      <form action="js-01.html" method="post" onsubmit="return validate_mail()">
      Email:<input type="text" id="email" size="30"/>
      <input type="submit" value="提交" />
      </form>
</body>
</html>